//
//  SPMapView.h
//  SPMapKit
//
//  Created by zhangbo on 2017/9/8.
//  Copyright © 2017年 zhangbo. All rights reserved.
//
//  自定义地图，api参考MKMapView，用法基本一致

#import <UIKit/UIKit.h>
#import "SPTiledView.h"
#import "MapAlgorithm.h"
#import <MapKit/MapKit.h>
#import "SPCanvasView.h"
#import "SPOverlayRenderer.h"
#import "ScaleRulerView.h"
#import "SPAnnotation.h"
#import "SPAnnotationView.h"
#import "SPOverlayRenderer.h"
#import "SPMapTypedef.h"
#import "SPMapDataManager.h"

typedef NS_ENUM(NSUInteger, SPMapPorvider) {
    BINGMAP_PROVIDER = 0,
    GOOGLEMAP_PROVIDER
};

@class SPMapView;

@protocol SPMapViewDelegate <NSObject>

-(SPAnnotationView*) mapView:(SPMapView*) mapView viewForAnnotation:(id <SPAnnotation>)annotation;

-(SPOverlayRenderer *)mapView:(SPMapView *)mapView rendererForOverlay:(id <SPOverlay>)overlay;

-(void) mapView:(SPMapView *)mapView didSelectAnnotationView:(SPAnnotationView *)view;

-(void) mapView:(SPMapView *)mapView didSelectOverlay:(id<SPOverlay>) overlay;

-(void) mapView:(SPMapView *)mapView didSelectBackground:(CLLocationCoordinate2D) gps;

@end

@interface SPMapView : UIView<UIScrollViewDelegate, SPTiledImageDelegate, SPCanvasDelegate, SPOverlayRendererDelegate, UIGestureRecognizerDelegate>
{
    SPTiledView *_tiledView;
    UIScrollView *_scrollView;
    SPCanvasView *_canvasView;
    NSMutableDictionary *_imgDic;
    ScaleRulerView *_rulerView;
    
    id<MapTileProviderProtocol> _provider;
}

- (id)initWithFrame:(CGRect)frame contentSize:(CGSize)contentSize;

@property (nonatomic, weak) id<SPMapViewDelegate> delegate;

/**
 最大缩放等级
 */
@property (nonatomic, assign) int maxLevelsOfZoom;

/**
 当前缩放等级
 */
@property (nonatomic, assign) int levelsOfZoom;

/**
 地图类型
 */
@property (nonatomic, assign) SPMapType mapType;

/**
 提供数据类型，目前支持bing和google
 */
@property (nonatomic, assign) SPMapPorvider mapProvider;

/**
 缩放倍数
 */
@property (nonatomic, assign) CGFloat zoomScale;
- (void)setZoomScale:(CGFloat)zoomScale animated:(BOOL)animated;

/**
 当前地图中心点的gps坐标
 */
@property (nonatomic, assign) CLLocationCoordinate2D centerGPS;

/**
 按照指定的地图等级定位到某地点

 @param gps gps
 @param level 缩放等级
 */
-(void) locate:(CLLocationCoordinate2D) gps level:(int) level;

/**
 定位到某地点

 @param gps gps坐标
 @param animated 有无动画
 */
-(void) locate:(CLLocationCoordinate2D) gps animated:(BOOL) animated;

/**
 定位到某地点后偏移给定值

 @param gps gps坐标
 @param offset 偏移
 */
-(void) locate:(CLLocationCoordinate2D) gps offset:(CGPoint) offset;

/**
 定位到某区域
 
 @param region 区域
 @param animated 是否显示动画
 */
-(void) locateToRegion:(MKCoordinateRegion)region animated:(BOOL) animated;

/**
 增加标识物

 @param annotation 标识物
 */
-(void) addAnnotation:(id<SPAnnotation>) annotation;

/**
 移除标识物

 @param annotation 标识物
 */
-(void) removeAnnotation:(id<SPAnnotation>) annotation;

/**
 移除所有标识物
 */
-(void) removeAllAnnotations;

/**
 增加覆盖物

 @param overlay 覆盖物
 */
-(void) addOverlay:(id<SPOverlay>) overlay;

/**
 移除覆盖物

 @param overlay 覆盖物
 */
-(void) removeOverlay:(id<SPOverlay>) overlay;

/**
 移除所有覆盖物
 */
-(void) removeALLOverlays;

/**
 标识物列表
 */
-(NSMutableArray*) annotations;

/**
 覆盖物列表
 */
-(NSMutableArray*) overlays;

/**
 刷新地图
 */
-(void) refresh;

/**
 刷新某标识物

 @param annotation 标识物
 */
-(void) refresh:(id<SPAnnotation>) annotation;

/**
 刷新所有覆盖物
 */
-(void) refreshOverlay;

@end
